<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>初识Vue</title>
		<!-- 引入Vue -->
		<script type="text/javascript" src="../js/vue.js"></script>
	</head>
	<body>
		
		<div id="root">
			<input type="text" placeholder="输入" v-model="keyWord"/>
			<ul>
				<li v-for="p in filPersons" :key="p.id">
                   {{p.name}}-{{p.age}}-{{p.sex}}
				</li>
			</ul>

		</div>

		<script type="text/javascript" >
			Vue.config.productionTip = false //阻止 vue 在启动时生成生产提示。

			//创建Vue实例
			new Vue({
				el:'#root',
				data:{
                  persons:[
				  {id:'001',name:'马冬梅',age:19,sex:'女'},
						{id:'002',name:'周冬雨',age:20,sex:'女'},
						{id:'003',name:'周杰伦',age:21,sex:'男'},
						{id:'004',name:'温兆伦',age:22,sex:'男'}
				  ],
				  keyWord:"",
				  filPersons:[]
				},
				watch:{
					keyWord:{
						immediate:true,
						headler(val){
							this.filPersons=this.persons.filter((p)=>{
                          return p.name.indexOf(val) !== -1
					   })
						}
                         
					}
				},
				computed: {
					filPersons(){
						this.filPersons=this.persons.filter((p)=>{
                          return p.name.indexOf(val) !== -1
					   })
					}
				}
			})

		</script>
	</body>
</html>

